import operate from '@dfeidao/atom-nodejs/db/operate';
import uuid from 'uuid';



interface Message {
	agarr: Array<{
		field: string;
		fieldtitle: string;
		fieldtype: string;
	}>;
	productid: string;
	role_type_id: string;
}

export default async function atom(msg: Message, action_id: string, session_id: string, spaceid: string) {
	const systemid = '12';

	const { exec, insert } = operate(action_id, session_id, systemid);
	msg.agarr.forEach((v) => {
		insert('pub_role_sysparams', {
			_id: uuid(),
			role_type_id: msg.role_type_id,
			productid: msg.productid,
			field: v.field,
			fieldtitle: v.fieldtitle,
			fieldtype: v.fieldtype
		});
	});


	const res = await exec();
	// console.log(res)
	if (res.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}

